<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 幕小铺科技（大连）有限公司 [ http://www.XXX.com ]
// +----------------------------------------------------------------------
// | 2020/03/14 jason wang
// +----------------------------------------------------------------------
namespace app\video\logic;
use think\facade\Hook;
use think\DB;
use util\Tree;
use think\facade\Debug;
use think\facade\Cache;
class Videologic{

	/**
     * 获取视频信息
     * @param  int $user_id  用户id
     * @param  int $play_id  视频id
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function get_play_info($user_id, $play_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' => $user_id,
                'play_id' => $play_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $info = datacache('VideoPlay') -> getInfoByPlayid($user_id, $play_id);
            if($info['code'] != 200){
                DB::rollback();
                return array_out(-1005, 'error');//前置错误 -1002
            }

            $result['playInfo'] = $info['data'];
				
            $rel = $this -> get_push_label_play_list($user_id, $play_id, $result['playInfo']['playType'], 1, 10);
            $result['playRelevantList'] = $rel['data'];//相关视频
            
            $rel = $this -> get_comment_list($user_id, $play_id, 1, 10);
            $result['playCommentList'] = $rel['data'];//视频评论
                
            
            /********业务逻辑********/
			// print_r($result);
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', (object)$result);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	/**
     * 删除视频
     * @param  int $user_id  用户id
     * @param  int $play_id  视频id
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function delete_video_play($user_id, $play_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' => $user_id,
                'play_id' => $play_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            //查询视频信息
            $video_play = model('VideoPlay', 'model') -> find($play_id);
            if(empty($video_play)){
                DB::rollback();
                return array_out(-1005, 'error1');//逻辑错误 -1005
            }
            $videoIds = $video_play -> video_id;
            
            //删除表中数据
            if($video_play -> play_operation_status == 1){
				$rel1 = model('VideoPlay', 'model') -> destroy(['uid' => $user_id, 'id' => $play_id]);
			}else{
				$rel1 = model('VideoPlay', 'model') -> where(['uid' => $user_id, 'id' => $play_id]) -> delete();
			}
			
            if(!$rel1){
                DB::rollback();
                return array_out(-1005, 'error2');//逻辑错误 -1005
            }

            //删除 阿里云 数据
            $rel = controller('Vodlogic', 'logic') -> deleteVideos($videoIds);
            if($rel['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error3');//逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
    /**
     * 视频评论
     * @param  int $user_id  用户id
     * @param  int $play_id  视频id
     * @param  int $content  内容
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function add_comment($user_id, $play_id, $content, $create_time = ''){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'play_id'		=> $play_id,
                'content' 		=> $content,
                'create_time' 	=> $create_time,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlayComment') -> addData($user_id, $play_id, $content, $create_time);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//业务逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $res['data']);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	/**
     * 视频评论回复
     * @param  int $user_id  	用户id
     * @param  int $play_id  	视频id
     * @param  int $comment_id  评论id
	 * @param  int $r_uid  		回复的回复id（0 普通回复）
     * @param  int $content  	内容
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function add_comment_reply($user_id, $play_id, $comment_id, $r_uid, $content){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'play_id' 		=> $play_id,
                'comment_id' 	=> $comment_id,
                'r_uid' 		=> $r_uid,
                'content'	 	=> $content,
            ];
            /********行为参数赋值（*）********/
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlayCommentReplay') -> addData($user_id, $play_id, $comment_id, $r_uid, $content);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//业务逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $res['data']);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
	}
    /**
     * 视频点赞
     * @param  int $user_id  用户id
     * @param  int $play_id  视频id
     * @param  int $create_time  点赞时间(管理员)
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function add_support($user_id, $play_id, $create_time = ''){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'play_id' 		=> $play_id,
                'create_time' 	=> $create_time,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlaySupport') -> addData($user_id, $play_id, $create_time);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//业务逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }

    }

    /**
     * 视频取消点赞
     * @param  int $user_id  用户id
     * @param  int $play_id  视频id
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function cancel_support($user_id, $play_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' => $user_id,
                'play_id' => $play_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlaySupport') -> deleteData($user_id, $play_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//业务逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

    /**
     * 视频评论列表
     * @param  int $user_id  用户id
     * @param  int $play_id  视频id
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function get_comment_list($user_uid, $play_id, $page, $page_size){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' => $user_uid,
                'play_id' => $play_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			if($page == 1){
				$list = datacache('VideoPlayComment', 'datacache') -> getPlayCommentList($play_id, $cache = true);
            }else{
                $list = datacache('VideoPlayComment', 'datacache') -> getPlayCommentList($play_id, $cache = false);
            }
            $list_data = $list['data'];
            $count = count($list_data);//总条数
            $start=($page-1)*$page_size;//偏移量，当前页-1乘以每页显示条数
            $rel_list = array_slice($list_data,$start,$page_size);
			
            $result = [];
            foreach ($rel_list as $key => $value) {
                //评论标准 对象
                $commentInfo = datacache('VideoPlayComment', 'datacache') -> getDataByCommentid($user_uid, $value['id']);
                if($commentInfo['code'] != 200) continue;
            	$result[] = $commentInfo['data'];
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $result);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }

    }
	/**
     * 视频评论 回复列表
     * @param  int $user_uid  	用户id
     * @param  int $comment_id  评论id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function get_reply_list($user_uid, $comment_id, $page, $page_size){
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		=> $user_uid,
                'comment_id'	=> $comment_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			if($page == 1){
				$list = datacache('VideoPlayCommentReplay', 'datacache') -> getPlayCommentReplayList($comment_id, $cache = true);
            }else{
                $list = datacache('VideoPlayCommentReplay', 'datacache') -> getPlayCommentReplayList($comment_id, $cache = false);
            }
            $list_data = $list['data'];
            $count = count($list_data);//总条数
            $start=($page-1)*$page_size;//偏移量，当前页-1乘以每页显示条数
            $rel_list = array_slice($list_data,$start,$page_size);
			
            $result = [];
            foreach ($rel_list as $key => $value) {
				$info = datacache('VideoPlayCommentReplay', 'datacache') -> getDataByReplyid($user_uid, $value['id']);
                if($info['code'] != 200) continue;
            	$result[] = $info['data'];
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            return array_out(200, 'success', $result);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
	}
	
	/**
     * 查询某人视频
     * @param  int $user_uid  被查询用户的ID
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
    public function others_video_list($user_id, $user_uid){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 	=> $user_id,
                'user_uid' 	=> $user_uid,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            //查询用户视频列表
			$list = model('VideoPlay') -> getListByUid($user_uid, $play_operation_status = 1);
			$list = self::returnBaceArray($user_id, $list['data']);
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
    
	/**
     * 我收藏的视频
     * @param  int $user_id   用户id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function collect_video_list($user_id){
        //DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 	=> $user_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                //DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            //查询用户视频列表
			$list = model('VideoPlayCollect') -> getListByUid($user_id);
			$list = self::getMyVideoListInfo($user_id, $list['data']);
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                //DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			//DB::commit();
            return array_out(200, 'success', $list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			//DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }

	}
	
	/**
     * 我点赞的视频
     * @param  int $user_id   用户id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function support_video_list($user_uid){
        //DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 	=> $user_uid,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                //DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            //查询用户视频列表
			$list = model('VideoPlaySupport') -> getListByUid($user_uid);
			$list = self::getMyVideoListInfo($user_uid, $list['data']);
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                //DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			//DB::commit();
            return array_out(200, 'success', $list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			//DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
	}
	
	/**
     * 视频评论点赞
     * @param  int $user_id   	用户id
     * @param  int $comment_id  评论id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function add_comment_support($user_id, $comment_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'comment_id' 	=> $comment_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlayCommentSupport') -> addData($user_id, $comment_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
	}
	
	/**
     * 视频评论取消点赞
     * @param  int $user_id   	用户id
     * @param  int $comment_id  评论id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function cancel_comment_support($user_id, $comment_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'comment_id' 	=> $comment_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlayCommentSupport') -> deleteData($user_id, $comment_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
	}
	
	/**
     * 视频评论回复点赞
     * @param  int $user_id   	用户id
     * @param  int $reply_id  	回复id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function add_reply_support($user_id, $reply_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'reply_id' 		=> $reply_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlayCommentReplaySupport') -> addData($user_id, $reply_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
	}
	
	/**
     * 视频评论回复取消点赞
     * @param  int $user_id   	用户id
     * @param  int $reply_id  	回复id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function cancel_reply_support($user_id, $reply_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'reply_id' 		=> $reply_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res = model('VideoPlayCommentReplaySupport') -> deleteData($user_id, $reply_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//逻辑错误 -1005
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
	}
	
	/**
     * 我的评论/回复里列表
     * @param  int $user_id   	用户id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function my_comment_reply_list($user_id){
        //DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                //DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $page       = input('page');
            $page_size  = input('page_size');
            if($page == 1){
                $list = controller('video/VideoPlay', 'datacache') -> myCommentReplyList($user_id, $cache = true);
            }else{
                $list = controller('video/VideoPlay', 'datacache') -> myCommentReplyList($user_id, $cache = false);
            }
            if($list['code'] != 200) return array_out(-1003, 'error');//后置错误 -1003
            $list_data = $list['data'];

            $count = count($list_data);//总条数
            $start=($page-1)*$page_size;//偏移量，当前页-1乘以每页显示条数
            $rel_list = array_slice($list_data,$start,$page_size);

            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                //DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			//DB::commit();
            return array_out(200, 'success', $rel_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			//DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
		
	}
	
	/**
     * 视频举报
     * @param  int 	  $user_id     用户id
     * @param  int 	  $report_id     举报的id
     * @param  int 	  $reason      举报理由id
     * @param  string $describe    举报详情
     * @param  string $img_url_1   图片1
     * @param  string $img_url_2   图片2
     * @param  string $img_url_3   图片3
     * @param  string $img_url_4   图片4
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function add_report($user_id, $report_type, $report_id, $reason, $describe, $img_url_1, $img_url_2, $img_url_3, $img_url_4){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'report_type'   => $report_type,
                'report_id'     => $report_id,
                'reason' 		=> $reason,
                'describe' 		=> $describe,
                'img_url_1' 	=> $img_url_1,
                'img_url_2' 	=> $img_url_2,
                'img_url_3' 	=> $img_url_3,
                'img_url_4' 	=> $img_url_4,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            switch ($report_type) {
                case 1://视频
                    $play_info =  model('VideoPlay') -> find($report_id);
                    $r_uid = $play_info -> uid;
                    $play_id = $report_id;
                    $comment_id = $reply_id = '';
                    break;
                case 2://评论
                    $play_info =  model('VideoPlayComment') -> find($report_id);
                    $r_uid = $play_info -> uid;
                    $comment_id = $report_id;
                    $play_id = $reply_id = '';
                    break;
                case 3://回复
                    $play_info =  model('VideoPlayCommentReplay') -> find($report_id);
                    $r_uid = $play_info -> uid;
                    $reply_id = $report_id;
                    $play_id = $comment_id = '';
                    break;
                default:
                    DB::rollback();
                    return array_out(-1005, 'error1');
                    break;
            }
            $res =  model('VideoPlayReport') -> addData($user_id, $report_type, $play_id, $comment_id, $reply_id, $r_uid, $reason, $describe, $img_url_1, $img_url_2, $img_url_3, $img_url_4);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error2');
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
            return array_out(-9999, $e->getMessage());
            //dump($e->getMessage());
        }
		
	}
	
	/**
     * 视频收藏
     * @param  int 	  $user_id     用户id
     * @param  int 	  $play_id     视频id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function add_collect($user_id, $play_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'play_id' 		=> $play_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res =  model('VideoPlayCollect') -> addData($user_id, $play_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//后置错误 -1003
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
		
	}
	
	/**
     * 视频取消收藏
     * @param  int 	  $user_id     用户id
     * @param  int 	  $play_id     视频id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function cancel_collect($user_id, $play_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'play_id' 		=> $play_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res =  model('VideoPlayCollect') -> deleteData($user_id, $play_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//后置错误 -1003
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
		
	}
	
	/**
     * 删除视频评论(软删除)
     * @param  int 	  $user_id     		用户id
     * @param  int 	  $comment_id     	评论id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function cancel_comment($user_id, $comment_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'comment_id' 	=> $comment_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res =  model('VideoPlayComment') -> deleteData($comment_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//后置错误 -1003
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
		
	}
	
	/**
     * 删除视频评论回复(软删除)
     * @param  int 	  $user_id     		用户id
     * @param  int 	  $reply_id     	回复id
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
	public function cancel_comment_reply($user_id, $reply_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
                'reply_id' 		=> $reply_id,
            ];

            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $res =  model('VideoPlayCommentReplay') -> deleteData($reply_id);
            if($res['code'] <= 0){
                DB::rollback();
                return array_out(-1005, 'error');//后置错误 -1003
            }
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
		
    }
    
    /**
     * 用户关注的视频列表
     * @param  int 	  $user_uid     		用户id
     * @author baoshi
     * @return mixed
     */
	public function get_follow_play_list($user_id, $page_size){
        DB::startTrans();//启动事务
        //try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 		=> $user_id,
            ];

            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			$page       = input('page');
            $page_size  = input('page_size');
			
            
            $list = controller('Pushlogic', 'logic') -> follow_play_push_list($user_id, $page_size);

		
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $list['data']);
            /********逻辑返回********/
			
        /* } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        } */
		
    }
    
    /**
     * 用户首页推荐
     * @param  int 	  $user_uid     		用户id（游客不填写）
     * @author baoshi
     * @return mixed
     */
	public function get_push_play_list($user_uid, $page, $page_size, $class_id=0){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		=> $user_uid,
            ];
            //Debug::remark('begin1');
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $page_size = intval($page == 1 ? $page_size-2 : $page_size);
            $page_size = $page_size >=0 ? $page_size : 0;
            
            //首页推送视频
            if($user_uid > 0){
                
                //$rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushListByUid($user_uid,$play_type=1, $page_size);//用户推荐
                //if($user_uid == 76){
                    $rel2 = datacache('VideoPlay', 'datacache') -> getPushListXin($user_uid, $play_type = 1, $class_id, $page_size);//用户推荐
                    if(empty($rel2)){
                        $rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushList($page_size, $class_id, $play_type=1);//游客推荐
                    }
                    
                    //dump($rel2);
                //}
            }else{
                $rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushList($page_size, $class_id, $play_type=1);//游客推荐
            }

            $rel_list2 = [];
            foreach ($rel2['data'] as $key => $value) {
                $rel_list2[] = [
                    'type' => 3,
                    'data3' => (object)$value,
                    'data2' => [],
                    'data1' => [],
                ];
            }
            
            if($page == 1){
                //首页推荐轮播
                $rel1 = datacache('VideoPlay', 'datacache') -> getIndexRecommendPushListByUid($num = 10);
            
                //热门用户排行
                $rel3 = datacache('user_center/UcMemberCount', 'datacache') -> getHotRankList($user_uid, $num = 10);
 
                $rel_list = [];
                $rel_list = [
                    [
                        'type' => 1,
                        'data1' => (array)$rel1['data'],
                        'data2' => [],
                        'data3' => (object)[],
                    ],
                    [
                        'type' => 2,
                        'data2' => (array)$rel3['data'],
                        'data1' => [],
                        'data3' => (object)[],
                    ],
                   
                ];
                
                
                //dump($rel_list2);die;
                //合并数组
                $return_list = array_merge($rel_list, $rel_list2);
            }else{
                $return_list = $rel_list2;
            }
            
            

            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            DB::commit();
            
            return array_out(200, 'success', $return_list);
            /********逻辑返回********/
			
         } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

    /**
     * 用户首页推荐
     * @param  int 	  $user_uid     		用户id（游客不填写）
     * @author baoshi
     * @return mixed
     */
	public function get_push_play_list_type3($user_uid, $page, $page_size){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		=> $user_uid,
            ];
            //Debug::remark('begin1');
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $page_size = intval($page == 1 ? $page_size-2 : $page_size);
            $page_size = $page_size >=0 ? $page_size : 0;
            
            //首页推送视频
            if($user_uid > 0){
                
                //$rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushListByUid($user_uid,$play_type=1, $page_size);//用户推荐
                //if($user_uid == 76){
                    $rel2 = datacache('VideoPlay', 'datacache') -> getPushListXin($user_uid, $play_type = 3, $class_id = 0, $page_size);//用户推荐
                    if(empty($rel2)){
                        $rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushList($page_size, $class_id=0, $play_type=3);//游客推荐
                    }
                    
                    //dump($rel2);
                //}
            }else{
                $rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushList($page_size, $class_id=0, $play_type=3);//游客推荐
            }
            //dump($rel2);
            $rel_list2 = [];
            foreach ($rel2['data'] as $key => $value) {
                $rel_list2[] = [
                    'type' => 3,
                    'data3' => (array)$value,
                    'data2' => [],
                    'data1' => [],
                ];
            }

            if($page == 1){
                //首页推荐轮播
                $rel1 = datacache('VideoPlay', 'datacache') -> getIndexRecommendPushListByUid($num = 10);
            
                //热门用户排行
                $rel3 = datacache('user_center/UcMemberCount', 'datacache') -> getHotRankList($user_uid, $num = 10);
 
                $rel_list = [];
                $rel_list = [
                    [
                        'type' => 1,
                        'data1' => (array)$rel1['data'],
                        'data2' => [],
                        'data3' => (object)[],
                    ],
                    [
                        'type' => 2,
                        'data2' => (array)$rel3['data'],
                        'data1' => [],
                        'data3' => (object)[],
                    ],
                   
                ];
                
                
                //dump($rel_list2);die;
                //合并数组
                $return_list = array_merge($rel_list, $rel_list2);
            }else{
                $return_list = $rel_list2;
            }
            
            

            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            DB::commit();
            
            return array_out(200, 'success', $return_list);
            /********逻辑返回********/
			
         } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

    /**
     * 用户搜索
     * @param  int 	  $user_uid     		用户id（游客0）
     * @author baoshi
     * @return mixed
     */
	public function get_play_list_search($user_uid, $video_title, $video_type){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		    => $user_uid,
                'video_title' 		=> $video_title,
                'video_type' 		=> $video_type,
            ];
            //Debug::remark('begin1');
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

			$page       = input('page');
            $page_size  = input('page_size');
			
			$list = datacache('video/VideoPlay') -> getPushSearchList($user_uid, $video_title, $video_type);//视频集合
			
            $list_data = $list['data'];
            $count = count($list_data);//总条数
            $start=($page-1)*$page_size;//偏移量，当前页-1乘以每页显示条数
            $rel_list = array_slice($list_data,$start,$page_size);
            $return_list = $this -> returnBaceArray($user_uid, $rel_list);
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            DB::commit();
            return array_out(200, 'success', $return_list);
            /********逻辑返回********/
			
         } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }

    /**
     * 用户首页 长视频推荐
     * @param  int 	  $user_uid     		用户id（游客不填写）
     * @author baoshi
     * @return mixed
     */
	public function get_push_play_long_list($user_uid, $page,$page_size, $class_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		=> $user_uid,
            ];

            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $page_size = intval($page == 1 ? $page_size-1 : $page_size);
            $page_size = $page_size >=0 ? $page_size : 0;

            //首页推送视频
            if($user_uid > 0){
                //$rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushListByUid($user_uid, $play_type=2, $page_size, $class_id);//用户推荐
                $rel2 = datacache('VideoPlay', 'datacache') -> getPushListXin($user_uid, $play_type = 2, $class_id, $page_size);//用户推荐
                if(empty($rel2['data'])){
                    $rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushList($page_size, $class_id, $play_type=2);//游客推荐
                }

                 
            }else{
                $rel2 = datacache('VideoPlay', 'datacache') -> getIndexOnePushList($page_size, $class_id, $play_type=2);//游客推荐
            }
            
            $rel_list2 = [];
            foreach ($rel2['data'] as $key => $value) {
                $rel_list2[] = 	[
                    'type' => 3,
                    'data3' => (object)$value,
                    'data2' => [],
                    'data1' => [],
                ];
            }

            if($page == 1){
                //热门用户排行
                $rel3 = datacache('user_center/UcMemberCount', 'datacache') -> getHotRankList($user_uid, $num = 10);
                
                $rel_list = [];
                $rel_list = [
                    [
                        'type' => 2,
                        'data2' => (array)$rel3['data'],
                        'data1' => [],
                        'data3' => (object)[],
                    ],
                ];
                //合并数组
                $return_list = array_merge($rel_list, $rel_list2);
            }else{
                $return_list = $rel_list2;
            }
            
            
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $return_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 视频分类查询
     * @param  int 	  $pid     		分类id（0为顶级分类）
     * @author shqiang
     * @return mixed
     */
	public function get_video_class(){
        try{
            /********行为参数赋值（*）********/
            $params = [
                //'pid' 		=> $pid,
            ];

            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/
            $lists = model('VideoPlayClass')->with('VideoPlayClassContact', 'LEFT')->field('id,pid,title') -> order('sort asc,id asc') -> select();
            
            foreach($lists as $key => $value){
                $label =[];
				foreach($value['video_play_class_contact'] as $val){
                    if(isset($val -> get_video_play_class_label)){
                        $label[] = [
							'id' 	=>	(int)$val -> get_video_play_class_label -> id,
							'title' =>	(string)$val -> get_video_play_class_label -> title
						];
                    }
					
				}
				$list[] = [
						'id' 		=> (int)$value -> id,
						'pid' 		=> (int)$value -> pid,
						'title' 	=> (string)$value -> title,
						'label' 	=> (array)$label,
					];
            }
            //dump($list);
            $list_child = Tree::toLayer($list, $pid = 0, $max_level = 0, $curr_level = 0);
            
			$list = [];
			$label = [];
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            return array_out(200, 'success', $list_child);
            /********逻辑返回********/
			
         } catch (\Exception $e) {
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        } 
    }

    /**
     * 视频分类查询1
     * @param  int 	  $pid     		分类id（0为顶级分类）
     * @author shqiang
     * @return mixed
     */
	public function get_video_class_level1(){
        try{
            /********行为参数赋值（*）********/
            $params = [
                //'pid' 		=> $pid,
            ];

            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/
            // $map = [];
            // $map['pid'] = 0;
            // $lists = model('VideoPlayClass') -> where($map)->field('id,pid,title') -> select()->toArray();
            $rel = datacache('VideoPlayClass', 'datacache') -> getPlayClassListLevel1();
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            return array_out(200, 'success', $rel);
            /********逻辑返回********/
			
         } catch (\Exception $e) {
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        } 
    }
	
	
	/**
     * 视频分类标签查询
     * @param  int 	  $pid     		分类id
     * @author shqiang
     * @return mixed
     */
	public function get_video_class_label($pid){
        try{
            /********行为参数赋值（*）********/
            $params = [
                'pid' 		=> $pid,
            ];

            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/
            $res =  model('VideoPlayClassContact') -> getListByLabelID($pid);
			$list = [];
			foreach($res['data'] as $value){
				if(isset($val -> get_video_play_class_label)){
					$list[] = [
						'id' 	=> (int)$value -> get_video_play_class_label -> id,
						'title' => (string)$value -> get_video_play_class_label -> title
					];
				}
			}
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            return array_out(200, 'success', $list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 视频列表 标准化输出（关联视频表videp_play list版）
     * @param  int 	  $int    用户id
     * @param  array 	  $list    视频表数组
     * @author baoshi
     * @return array
     */
	public function getMyVideoListInfo($uid, $list){
		//用户信息
		$result_list=$value_list = [];
		foreach($list as $key => $val){
			if(isset($val -> get_video_play)){
				$info = $val -> get_video_play;
				
				if($val -> get_video_play -> play_type == 2){
					$video_info = model('video/VideoPlay') -> getPlayFatherById($val -> get_video_play -> id);
					if($video_info['code']  == 200){
						$info = $video_info['data'];
					}
				}
				$value_list[] = $info;//关联视频
			}
        }
        $result_list = $this -> returnBaceArray($uid, $value_list);
		return $result_list;
    }
	
	/**
     * 短视频相关推荐
     * @param  int 	  $user_uid     		用户id（游客不填写）
     * @author shiqiang
     * @return mixed
     */
	public function get_short_label_play_list($user_uid, $page, $page_size){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		=> $user_uid,
            ];
            //Debug::remark('begin1');
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/	
            $return_list = datacache('VideoPlay', 'datacache') -> getPushListXin($user_uid, $play_type = 1, $class_id = 0, $page_size);//用户推荐
            if(empty($return_list)){
                $return_list = datacache('VideoPlay', 'datacache') -> getIndexOnePushList($page_size, $class_id=0, $play_type=1);//游客推荐
            }

            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            DB::commit();
            return array_out(200, 'success', $return_list['data']);
            /********逻辑返回********/
			
         } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 相关视频(通过标签关联)
     * @param  int 	  $user_uid     	用户id
     * @param  int 	  $play_id     		视频id
     * @param  int 	  $play_type     	视频类型
     * @param  int 	  $page     		分页
     * @author shiqiang
     * @return mixed
     */
	public function get_push_label_play_list($user_uid, $play_id, $play_type, $page, $page_size = 10){
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		=> $user_uid,
                'play_id' 		=> $play_id,
                'play_type' 	=> $play_type,
                'page' 			=> $page,
            ];

            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			$rel = datacache('VideoPlayLabelRelation', 'datacache') -> getLabelVideoPushList($user_uid, $play_id, $play_type, $page, $page_size);
			$rel_list = $rel['data'];
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/
			
            return array_out(200, 'success', $rel_list);
        } catch (\Exception $e) {
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
    
    /**
     * 查询某人视频
     * @param  int $user_uid  被查询用户的ID
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
    public function mymcn_video_list($user_id, $state){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_id' 	=> $user_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            //查询用户视频列表
            $map = [];
            $map[] = ['uid', '=', $user_id];
            $map[] = ['play_operation_status', '<>', 4];
            if(is_numeric($state)) $map[] = ['play_operation_status', '=', $state];
            $list = model('VideoPlay') ->where($map) -> order('create_time' ,'desc') -> paginate();
            //dump(model('VideoPlay') -> getLastSql(1));
            $list_arr = $list->toArray();
            $rel_list = self::returnBaceArray($user_id, $list);
            $result_list['total']  = $list_arr['total'];//总数
            $result_list['current_page']   = $list_arr['current_page'];//页码
            $result_list['last_page']   = $list_arr['last_page'];//总页数
            $result_list['per_page']    = $list_arr['per_page'];//每页条数
            $result_list['data']        = $rel_list;//每页条数
            
            /********业务逻辑********/

            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $result_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 用户观看视频时间
     * @param  int 	  $play_id     		视频id
     * @param  int 	  $user_uid     		用户id
     * @param  int 	  $seconds     		观看时长
     * @author shqiang
     * @return mixed
     */
	public function add_play_watchcount($user_uid, $play_id, $seconds){
        try{
            /********行为参数赋值（*）********/
            $params = [
                'user_uid' 		=> $user_uid,
                'play_id' 		=> $play_id,
                'seconds' 		=> $seconds,
            ];

            /********行为参数赋值（*）********/
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/
			$watch_seconds = model('video/VideoPlayWatchcount') -> getWatchSecondsByid($user_uid, $play_id);
			
			if($watch_seconds['code'] == 200){
				//如果 本次观看时常，超过上次观看时常 更新数据
				if($watch_seconds['data']['seconds'] < $seconds){
					$rel = model('VideoPlayWatchcount') -> editData($watch_seconds['data']['id'], $seconds);
					if($rel['code'] < 0){
						return array_out(-1005, 'error3');
					}
				}
			}else{
				//当日首次观看
				$rel = model('VideoPlay') -> find($play_id);//获取videoid
				$video_id = $rel -> video_id;
				//视频 阿里信息
				$aliVideoInfo = datacache('VideoPlay') -> getAliVideoInfoByVideoid($video_id);//用户统计缓存
				if($aliVideoInfo <= 0 || !isset($aliVideoInfo['data']['playUrl'])){
					return array_out(-1005, 'error1');
				}
				$duration = $aliVideoInfo['data']['playUrl'][0]['duration'];
				
				$rel = model('VideoPlayWatchcount') -> addData($user_uid, $play_id, $seconds, $duration);
				if($rel['code'] < 0){
					return array_out(-1005, 'error2');
				}
				if($user_uid > 0){
					$video_info = model('video/VideoPlay') -> getPlayinfoByPlayid($play_id);
					$play_type = $video_info['data']['play_type'];//关联的视频id	
					
					$rel = model('video/VideoPlayIndexpush') -> addData($user_uid, $play_id, $play_type);
					
					if($rel['code'] < 0){
						return array_out(-1005, 'error2');
					}
				}
			}
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
            return array_out(200, 'success');
            /********逻辑返回********/
			
         } catch (\Exception $e) {
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        } 
    }
	
	/**
     * 视频举报
     * @author shqiang
     * @return mixed
     */
	public function play_report_list(){
		try{
			/********行为参数赋值（*）********/
			$params = [
				// 'user_id' 		=> $user_id,
			];
			/********前置行为********/
			$hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
			if($hook_rel['code'] < 0){
				DB::rollback();
				return array_out(-1002, $hook_rel['message']);//前置错误 -1002
			}
			/********前置行为********/
			
			//获取视频举报
			$result = play_report();
			
			/********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/
			
			return array_out(200, 'success', $result);
		}catch (\Exception $e) {
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        } 
	}
	
    /**
     * 视频列表 标准化输出（视频表videp_play list版）
     * @param uid 		int 用户id（0为游客）
     * @param  array 	  $list    视频表数组
     * @author baoshi
     * @return array
     */
	public function returnBaceArray___________($uid, $list){

        $result_list = [];
        foreach ($list as $key => $value) {
            
            //用户信息 缓存
            $member_info = model('user_center/Member', 'model\user') -> getDateByUid($value['uid']);
            $member_info = $member_info['data']; 
            //用户统计 缓存
            $UcMemberCount_info = datacache('user_center/UcMemberCount') -> getInUfoByUid($value['uid']);//用户统计缓存
            $UcMemberCount_info = $UcMemberCount_info['data'];
            //查询视频资源 缓存
            $map = [];
            $map['play_id'] = $value['id'];
            $resources_obj = model('VideoPlayResources') -> where($map) -> cache(60*60) -> select();
            if($resources_obj) $resources = $resources_obj->toArray();

            //判断信息是否 完整
            if((!$value['cover_url'] || !$value['duration'] || count($resources) < 2) && $value['play_operation_status'] != 3){ dump($value['id']);dump(count($resources));
                $timeout = 3600;
                $videobase = controller('Vodlogic', 'logic')->getPlayInfo($value['video_id'], $timeout);//获取视频播放信息
                if($videobase['code'] == 200){
                    $cover_url = isset($videobase['data']['VideoBase']['CoverURL']) ? $videobase['data']['VideoBase']['CoverURL'] : '';//视频截图
                    $Duration = $videobase['data']['VideoBase']['Duration'];//视频时长

                    //更新时长和缩略图
                    $map = [];
                    $map['id']	= $value['id'];
                    $data = [];
                    $data['cover_url'] = $cover_url;
                    $data['duration'] = $Duration;
                    $res1 = model('VideoPlay')->where($map)->update($data);//dump($res1);

                    //赋值
                    $value['cover_url'] = $cover_url;
                    $value['duration'] = $Duration;

                    //添加播放数据源
                    $map = [];
                    $map['play_id'] = $value['id'];
                    model('VideoPlayResources') -> where($map) -> delete();

                    //清空数据源
                    $resources = [];
                    foreach ($videobase['data']['PlayInfoList']['PlayInfo'] as $key1 => $value1) {
                        $resources[] = [
                            'play_id'           => $value['id'],
                            'Size'              => $value1['Size'],
                            'Definition'        => $value1['Definition'],
                            'Fps'               => $value1['Fps'],
                            'Duration'          => $value1['Duration'],
                            'ModificationTime'  => $value1['ModificationTime'],
                            'Specification'     => $value1['Specification'],
                            'Bitrate'           => $value1['Bitrate'],
                            'Encrypt'           => $value1['Encrypt'],
                            'PreprocessStatus'  => $value1['PreprocessStatus'],
                            'Format'            => $value1['Format'],
                            'PlayURL'           => $value1['PlayURL'],
                            'NarrowBandType'    => $value1['NarrowBandType'],
                            'CreationTime'      => $value1['CreationTime'],
                            'Height'            => $value1['Height'],
                            'Width'             => $value1['Width'],
                            'JobId'             => $value1['JobId'],
                            'create_time'       => time(),
                            'update_time'       => time(),
                        ];
                    }
                    model('VideoPlayResources') -> insertAll($resources);
                }else{
                    continue;
                }
            }

             foreach ($resources as $key2 => $value2) {
                $playUrl[] = [
                    'definition' => $value2['Definition'],
                    'playURL'    => $value2['PlayURL'],
                    'width'      => $value2['Width'],
                    'height'     => $value2['Height'],
                    'duration'   => $value2['Duration'],
                ];
            }

            //是否点赞
            $support = model('VideoPlaySupport') -> isSupport($uid, $value['id']);//是否点赞
            $isSupport = $support['code'] == 200 ? 1 : 0;
            
            //视频分类 缓存
            $videoclass = datacache('VideoPlayClass') -> getPlayClassNameByClassid($value['video_classid']);
              
            //视频标签 缓存
            $lable_arr = datacache('VideoPlayLabelRelation') -> getPlayLable($value['id']);

            //获取凭证
            /* $PlayAuth = controller('Vodlogic', 'logic') -> getVideoPlayAuth($value['video_id']);
            if($PlayAuth['code'] < 0){
                continue;
                //return array_out(-1005, $result['message']);//逻辑错误 - 1005
            }
            $PlayAuth = $PlayAuth['data']['PlayAuth']; */
            
            //评论数
            //dump($value);dump($value->getData('play_operation_status'));die;
            /* $result_list[] = [
                'type'                  => (int)3,
                'authorId'              => (int)$value['uid'],
                'authorNickName'        => (string)$member_info -> nick_name,
                'authorAvatorUrl'       => (string)get_avatar_user($value['uid']),
                'authorFansTimes'       => (string)$UcMemberCount_info['fans_times'],//粉丝数
                'authorTitle'           => (string)'CEO头衔',//头衔
                'playCommentTimes'      => (string)$value['comment_times'],//评论数
                //'playCommentTimes'      => (string)$get_video_play -> comment_times,//作品评论数
                'playSupportTimes'      => (string)$value['support_times'],//作品点赞数
                'playId'                => (int)$value['id'],
                'playVideoId'           => (string)$value['video_id'],
                'playTitle'             => (string)$value['main_title'],
                'playDecription'        => (string)$value['description'],
                'playDatetime'          => (string)date('Y-m-d H:i:s', $value['create_time']),
                'playType'              => (int)$value['play_type'],
                'isImmerse'             => (int)$value['is_immerse'],
                'isRotate'              => (int)$value['is_rotate'],
                'isOriginal'            => (int)$value['is_original'],
                'playUrl'               => (array)$playUrl,
                'coverUrl'              => (string)$value['cover_url'],
                'isSupport'             => (int) $isSupport,//是否点赞
                'videoClassid'          => (int)$value['video_classid'],
                'videoLable'            => (array)$lable_arr,
                'state'                 => $value['play_operation_status'],
                //'playAuth'              => $PlayAuth,
            ]; */
        }
        
        return $result_list;
    }

    /**
     * 视频列表 标准化输出（视频表videp_play list版）
     * @param uid 		int 用户id（0为游客）
     * @param  array 	  $list    视频表数组
     * @author baoshi
     * @return array
     */
	public function returnBaceArray($uid, $list){
        $result_list = [];
        foreach ($list as $key => $value) {
            $info = datacache('VideoPlay') -> getInfoByPlayid($uid, $value['id']);
            if($info['code'] != 200) continue;
            $result_list[] = $info['data'];
        }
        
        return $result_list;
    }

}